package com.itheima.cases_demo.local_date_time;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.chrono.ChronoLocalDate;

public class Test {
    public static void main(String[] args) {
        // 测试 LocalDate 类

        // 获取当前日期对象
        LocalDate now = LocalDate.now();
        System.out.println(now); // 2023-07-30

        // 获取日期信息
        int year = now.getYear(); // 获取年
        System.out.println(year); // 2023

        int monthValue = now.getMonthValue();// 获取月
        System.out.println(monthValue); // 7

        int dayOfMonth = now.getDayOfMonth(); // 获取月份的第几天
        System.out.println(dayOfMonth); // 30

        int dayOfYear = now.getDayOfYear(); // 一年的第几天
        System.out.println(dayOfYear); // 211

        int dayOfWeek = now.getDayOfWeek().getValue(); // 周几
        System.out.println(dayOfWeek); // 7

        System.out.println("---------------");

        // 反实例化
        LocalDate last = LocalDate.of(2013, 12, 12);
        System.out.println(last);  // 2013-12-12

        LocalDate localDateFixYear = last.withYear(2023); // 直接修改年的值
        System.out.println(localDateFixYear);

        LocalDate localDateFixMonth = last.withMonth(3); // 直接修改月份
        System.out.println(localDateFixMonth);

        LocalDate localDatePlusYear = last.plusYears(3); // 加3年
        System.out.println(localDatePlusYear);

        LocalDate localDatePlusMonth = last.plusMonths(5); // 加5个月
        System.out.println(localDatePlusMonth);

        boolean equals = localDateFixMonth.equals(last); // 比较两个日期是否相等
        System.out.println(equals);

        boolean equals2 = last.equals(LocalDate.of(2013, 12, 12));
        System.out.println(equals2);

        boolean isBefore = last.isBefore(LocalDate.of(2013, 12, 10));
        System.out.println(isBefore);

        boolean isAfter = last.isAfter(LocalDate.of(2015, 12, 3));
        System.out.println(isAfter);
    }
}
